<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::Filter::Utils::BitReader</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::Filter::Utils::BitReader</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/origami/filters_rb.html">
                origami/filters.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Class used to <a href="BitReader.html#M000342">read</a> a <a
href="../../String.html">String</a> as a stream of bits. Internally used by
some filters.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000338">eod?</a>&nbsp;&nbsp;
      <a href="#M000336">new</a>&nbsp;&nbsp;
      <a href="#M000343">peek</a>&nbsp;&nbsp;
      <a href="#M000339">pos</a>&nbsp;&nbsp;
      <a href="#M000341">pos=</a>&nbsp;&nbsp;
      <a href="#M000342">read</a>&nbsp;&nbsp;
      <a href="#M000337">reset</a>&nbsp;&nbsp;
      <a href="#M000340">size</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000336" class="method-detail">
        <a name="M000336"></a>

        <div class="method-heading">
          <a href="#M000336" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(data)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000336-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000336-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 123</span>
123:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">data</span>)
124:           <span class="ruby-ivar">@data</span> = <span class="ruby-identifier">data</span>
125:           <span class="ruby-identifier">reset</span>
126:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000338" class="method-detail">
        <a name="M000338"></a>

        <div class="method-heading">
          <a href="#M000338" class="method-signature">
          <span class="method-name">eod?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if end of data has been reached.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000338-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000338-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 139</span>
139:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eod?</span>
140:           <span class="ruby-ivar">@ptr_byte</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">size</span>
141:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000343" class="method-detail">
        <a name="M000343"></a>

        <div class="method-heading">
          <a href="#M000343" class="method-signature">
          <span class="method-name">peek</span><span class="method-args">(length)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reads <em>length</em> bits as a Fixnum. Does not advance <a
href="BitReader.html#M000342">read</a> pointer.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000343-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000343-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 183</span>
183:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">peek</span>(<span class="ruby-identifier">length</span>)
184:           <span class="ruby-keyword kw">return</span> <span class="ruby-constant">BitReaderError</span>, <span class="ruby-value str">&quot;Invalid read length&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> 
185:           <span class="ruby-keyword kw">return</span> <span class="ruby-constant">BitReaderError</span>, <span class="ruby-value str">&quot;Insufficient data&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">size</span>
186: 
187:           <span class="ruby-identifier">n</span> = <span class="ruby-value">0</span>
188:           <span class="ruby-identifier">ptr_byte</span>, <span class="ruby-identifier">ptr_bit</span> = <span class="ruby-ivar">@ptr_byte</span>, <span class="ruby-ivar">@ptr_bit</span>
189: 
190:           <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
191:             <span class="ruby-identifier">byte</span> = <span class="ruby-ivar">@data</span>[<span class="ruby-identifier">ptr_byte</span>].<span class="ruby-identifier">ord</span>
192:     
193:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">ptr_bit</span>
194:               <span class="ruby-identifier">length</span> <span class="ruby-operator">-=</span> <span class="ruby-value">8</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">ptr_bit</span>
195:               <span class="ruby-identifier">n</span> <span class="ruby-operator">|=</span> ( <span class="ruby-identifier">byte</span> <span class="ruby-operator">&amp;</span> ((<span class="ruby-value">1</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value">8</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">ptr_bit</span>)) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) ) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">length</span>
196: 
197:               <span class="ruby-identifier">ptr_byte</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
198:               <span class="ruby-identifier">ptr_bit</span> = <span class="ruby-value">0</span>
199:             <span class="ruby-keyword kw">else</span>
200:               <span class="ruby-identifier">n</span> <span class="ruby-operator">|=</span> (<span class="ruby-identifier">byte</span> <span class="ruby-operator">&gt;&gt;</span> (<span class="ruby-value">8</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">ptr_bit</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">length</span>)) <span class="ruby-operator">&amp;</span> ((<span class="ruby-value">1</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">length</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
201:               <span class="ruby-identifier">length</span> = <span class="ruby-value">0</span>
202:             <span class="ruby-keyword kw">end</span>
203:           <span class="ruby-keyword kw">end</span>
204: 
205:           <span class="ruby-identifier">n</span>
206:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000339" class="method-detail">
        <a name="M000339"></a>

        <div class="method-heading">
          <a href="#M000339" class="method-signature">
          <span class="method-name">pos</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="BitReader.html#M000342">read</a> pointer position in
bits.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000339-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000339-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 146</span>
146:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pos</span>
147:           (<span class="ruby-ivar">@ptr_byte</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">3</span>) <span class="ruby-operator">+</span> <span class="ruby-ivar">@ptr_bit</span>
148:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000341" class="method-detail">
        <a name="M000341"></a>

        <div class="method-heading">
          <a href="#M000341" class="method-signature">
          <span class="method-name">pos=</span><span class="method-args">(bits)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the <a href="BitReader.html#M000342">read</a> pointer position in
bits.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000341-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000341-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 160</span>
160:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pos=</span>(<span class="ruby-identifier">bits</span>)
161:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">BitReaderError</span>, <span class="ruby-value str">&quot;Pointer position out of data&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">size</span>
162: 
163:           <span class="ruby-identifier">pbyte</span> = <span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>
164:           <span class="ruby-identifier">pbit</span> = <span class="ruby-identifier">bits</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">pbyte</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">3</span>)
165:           <span class="ruby-ivar">@ptr_byte</span>, <span class="ruby-ivar">@ptr_bit</span> = <span class="ruby-identifier">pbyte</span>, <span class="ruby-identifier">pbit</span>
166:           
167:           <span class="ruby-identifier">bits</span>
168:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000342" class="method-detail">
        <a name="M000342"></a>

        <div class="method-heading">
          <a href="#M000342" class="method-signature">
          <span class="method-name">read</span><span class="method-args">(length)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reads <em>length</em> bits as a Fixnum and advances <a
href="BitReader.html#M000342">read</a> pointer.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000342-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000342-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 173</span>
173:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">length</span>)
174:           <span class="ruby-identifier">n</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">peek</span>(<span class="ruby-identifier">length</span>)
175:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">length</span>
176: 
177:           <span class="ruby-identifier">n</span>
178:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000337" class="method-detail">
        <a name="M000337"></a>

        <div class="method-heading">
          <a href="#M000337" class="method-signature">
          <span class="method-name">reset</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Resets the <a href="BitReader.html#M000342">read</a> pointer.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000337-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000337-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 131</span>
131:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>
132:           <span class="ruby-ivar">@ptr_byte</span>, <span class="ruby-ivar">@ptr_bit</span> = <span class="ruby-value">0</span>, <span class="ruby-value">0</span>
133:           <span class="ruby-keyword kw">self</span>
134:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000340" class="method-detail">
        <a name="M000340"></a>

        <div class="method-heading">
          <a href="#M000340" class="method-signature">
          <span class="method-name">size</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the data <a href="BitReader.html#M000340">size</a> in bits.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000340-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000340-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters.rb, line 153</span>
153:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
154:           <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">3</span>
155:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>